package com.glorysoft.lipuxinpda.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.glorysoft.lipuxinpda.R;
import com.glorysoft.lipuxinpda.entity.ChangeSpotCheckInfoEntity;
import com.glorysoft.lipuxinpda.entity.CheckInfoDetailEntity;
import com.glorysoft.lipuxinpda.entity.SpotCheckInfoReturnEntity;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.ArrayList;
import java.util.List;

public class DaycheckRecyclerViewAdapter extends RecyclerView.Adapter<DaycheckRecyclerViewAdapter.ViewHolder>{

    private List<CheckInfoDetailEntity> mList;

    public void setmList(List<CheckInfoDetailEntity> mList) {
        this.mList = mList;

        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_check_type_detail, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CheckInfoDetailEntity entity = mList.get(position);

        holder.tv_check_type_detail_name.setText(entity.getVALUE());

        holder.rg_ok_ng.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_ok){
                    holder.rb_ok.setChecked(true);
                }else {
                    holder.rb_ng.setChecked(true);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return Math.max(mList.size(), 0);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_check_type_detail_name;
        private RadioGroup rg_ok_ng;
        private RadioButton rb_ok;
        private RadioButton rb_ng;
        private FreeUI_ClearEditText et_reason;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_check_type_detail_name = itemView.findViewById(R.id.tv_check_type_detail_name);
            rg_ok_ng = itemView.findViewById(R.id.rg_ok_ng);
            rb_ok = itemView.findViewById(R.id.rb_ok);
            rb_ng = itemView.findViewById(R.id.rb_ng);
            et_reason = itemView.findViewById(R.id.et_reason);
        }
    }
}
